package com.example.leon.demo.Activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.example.leon.demo.R;
import com.example.leon.demo.common.BaseActivity;

/**
 * Created by leon on 2016/3/26.
 */
public class FirstActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.first_activity);

        //初始化
        initIndex();
    }

    @Override
    protected void onActivityResult(int requestCode,int resultCode,Intent data){
        switch (requestCode){
            case 1:
                if(resultCode==RESULT_OK){
                    String returnedData=data.getStringExtra("data_return");
                    Log.d("first",returnedData);
                }
                break;
            default:
        }
    }


    protected void initIndex() {
        Button btn1 = (Button) findViewById(R.id.btn1);
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //显示调用 不传递参数
                actionStart(FirstActivity.this,"data1","data2");
                Log.d("FirstActivity", this.toString());
                //使用startActivityForResuat()
//                Intent intent=new Intent(FirstActivity.this,FirstActivity.class);
//                startActivityForResult(intent,1);


                //显示调用 传递参数
//                String data="hello secondactivity";
//                Intent intent=new Intent(FirstActivity.this,SecondActivity.class);
//                intent.putExtra("extra_data",data);
//                startActivity(intent);

                //隐式调用
//                Intent intent=new Intent("com.example.leon.demo.ACTION_START");
//                intent.addCategory("android.intent.category.DEFAULT");
//                startActivity(intent);

            }
        });

    }

    public static void actionStart(Context context,String data1,String data2){
        Intent intent=new Intent(context,HomeActivity.class);
//        intent.putExtra("param1",data1);
//        intent.putExtra("param2",data2);
        context.startActivity(intent);

    }


}
